#include <stdbool.h>
#include <stdio.h>
#include <string.h>

#define STACK_SIZE 100

char contents[STACK_SIZE];
int top = 0;

void make_empty(int index){
	index = 0;
}

bool is_empty(int index){
	return index == 0;
}

bool is_full(int index){
	return index == STACK_SIZE;
}

int push(char c, char* array, int index){
	if (is_full(index)){
		printf("stack overflow!");
		return -1;
	} else {
		array[index++] = c; 
		return index;
	}
}

char pop(char* array, int index){
	if (is_empty(index)){
		printf("stack underflow!");
	} else {
		return array[index-1];
	}
}



int main(){
	printf("Enter parentesse and/or braces: ");
	char c ;
	for(;;){
		c = getchar();
		if (c == '(' || c == '{' || c == ')' || c == '}'){
			top = push(c, contents, top);
		}
		if (c == '\n')
			break;
	}
	char outContent[STACK_SIZE];
	int outTop = -1;
	while(top > 0){
		if (outTop >= 0) {
			c = pop(contents, top);
			top = top - 1;
			if ((c == '(' && outContent[outTop] == ')') || (c == '{' && outContent[outTop] == '}')){
				outTop = outTop - 1;
			} else {
				outContent[outTop+1] = c;
				outTop = outTop + 1;
			}
		} else {
			c = pop(contents, top);
			outContent[outTop+1] = c;
			outTop = outTop + 1;
			top = top - 1;
		}
	}
	if (outTop < 0) 
		printf("Parentesse/braces are RIGHT\n");
	else
		printf("Parentesse/braces are WRONG\n");
}
